﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Collections;
using System.Linq;
using Orange.Lib.Effective;

namespace Orange.Lib.Effective
{
    namespace DynamicUse
    {
        public class Finance
        {
            private static decimal amount = 0;

            public static decimal Amount
            {
                get { return Finance.amount; }
                set { Finance.amount = value; }
            }
            public static void Add(Product p)
            {
                amount += p.Amount;
                Debug.WriteLine(string.Format("amount current: {0}" + amount.ToString()));
            }

            public static void Add(dynamic p)
            {
                amount += p.Amount;
                Debug.WriteLine(string.Format("amount current: {0}" + amount.ToString()));
            }
        }

        public class Display
        {
            public void Demo()
            {
                Product p = new Product { Amount = 10 };
                Box<int> b = new Box<int> { Amount = 5 };
                Finance.Add(p);
                Finance.Add(b);
                Console.ReadKey();

                Console.WriteLine("Size: {0}", 1);
            }
        }

        public static class Ext
        {
            public static IEnumerable<T> Convert<T>(this IEnumerable seq)
            {
                foreach (object item in seq)
                {
                    dynamic tmp = (dynamic)item;
                    yield return (T)tmp;
                }
            }
        }
    }
}
